<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>广告1遍</title>
    <style>
        .xiaomi {
            width: 512px;
            height: 400px;
            border: 1px solid #f00;
            margin: 100px auto;
            overflow: hidden;
            position: relative;
        }

        .xiaomi span {
            position: absolute;
            left: 0;
            width: 100%;
            height: 200px;
            cursor: pointer;
        }

        .up {
            top: 0;
        }

        .down {
            bottom: 0;
        }

        .xiaomi img {
            position: absolute;
            top: 0;
            left: 0;
        }
    </style>
</head>
<body>
<div class="xiaomi">
    <img src="images/mi.png" alt="" id="pic"/>
    <span class="up" id="goUp"></span>
    <span class="down" id="goDown"></span>
</div>
<script>
    var timer = null;
    var y = 0;
    var div=document.getElementsByClassName("xiaomi");
    var pic = document.getElementById("pic");
    var goUp = document.getElementById("goUp");
    var goDown = document.getElementById("goDown");
    goUp.onmouseover = function () {
        clearInterval(timer);
        timer = setInterval(function () {
            if (y > -1070) {
                y -= 3;
                pic.style.top=y+"px";
            }else {
                clearInterval(timer);
            }
        }, 15)
    };
    goDown.onmouseover=function(){
        clearInterval(timer);
        timer=setInterval(function(){
            if(y<0){
                y+=3;
                pic.style.top=y+"px"
            }else{
                clearInterval(timer)
            }
        },15)
    };
    goDown.parentNode.onmouseout=function(){
        clearInterval(timer);
    }
    goDown.parentNode.onclick= function () {
        clearInterval(timer);
    }
</script>
</body>
</html>